from pynput import keyboard
from pynput.keyboard import Listener

def press(key):  # 按键检测方法
    if key == keyboard.Key.home:
        print('home')
    elif key == keyboard.Key.ctrl_l:
        print('ctrl')
    elif key == keyboard.Key.esc:
        print('关闭监听')
        listener.stop()
    elif key.char == 'a':
        print('A')


"""对于这个键盘监听，个人理解是新开了一个线程进行工作"""
listener = Listener(on_press=press)  # 创建一个键盘监听对象
listener.start()  # 开时监听键盘

while True:
    pass
